﻿Imports Crystal.CLL
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports System.Data.SqlClient
Imports CrystalDataHub.BLL.DataHub.BusinessObject

Public Class ColumnListManager
#Region "Methods"
    Public Function GetColumnListUpdateDDInfo(ByVal pintProjectID As Integer) As IDataReader
        Dim Idrdata As IDataReader = Nothing
        Idrdata = DataFactory.CreateDataBase().ExecuteReader("CR_sp_DE_GetColumnListUpdateDDInfo", {pintProjectID})
        Return Idrdata
    End Function
    Public Function GetColumnListRegBanklist(ByVal pintProjectID As Integer) As IDataReader
        Dim Idrdata As IDataReader = Nothing
        Idrdata = DataFactory.CreateDataBase().ExecuteReader("CR_sp_DE_GetColumnListRegBanklistOthers", {pintProjectID})
        Return Idrdata
    End Function

    Public Function GetColumnListPreviousFinalisedListing(ByVal pintProjectID As Integer) As IDataReader
        Dim Idrdata As IDataReader = Nothing
        Idrdata = DataFactory.CreateDataBase().ExecuteReader("CR_sp_DE_GetColumnListPreviousFinalListing", {pintProjectID})
        Return Idrdata
    End Function
    Public Function UpdateColumnListEntities(ByVal strXML As String) As DataSet
        Return DataFactory.CreateDataBase().ExecuteDataSet("CR_sp_UpdateDataNDNIL", {strXML})
    End Function
    Public Function GetColumnListEntities(ByVal mintProjectID As Integer) As DataSet
        Return DataFactory.CreateDataBase().ExecuteDataSet("CR_sp_DE_ColumnListEntities", {mintProjectID})
    End Function

    Public Function GetEntityID(ByVal mstrSourceName As String) As Integer
        Return DataFactory.CreateDataBase().ExecuteScalar("CR_sp_DE_GetEntityID", {mstrSourceName})
    End Function

    Public Function GetCurrentDataSources(ByVal pintProjectID As Integer) As List(Of CurrentDataSources)
        Dim lstData As New List(Of CurrentDataSources)
        Dim lobjData As CurrentDataSources = Nothing
        Dim lentDB As Database = DataFactory.CreateDataBase()
        Try
            Using cmd As SqlCommand = lentDB.GetStoredProcCommand("CR_sp_DE_CurrentDataSources")
                'lentDB.AddInParameter(cmd, "SourceName", DbType.String, pstrSourceName)
                'lentDB.AddInParameter(cmd, "UserID", DbType.Int32, pintUserID)
                lentDB.AddInParameter(cmd, "ProjectID", DbType.Int16, pintProjectID)
                cmd.CommandTimeout = 0
                Using reader As IDataReader = lentDB.ExecuteReader(cmd)
                    Dim lintListingIDIndex As Int16 = reader.GetOrdinal("ListingID")
                    'Dim lstrListingNameIndex As Int16 = reader.GetOrdinal("ListingName")
                    Dim lintEntityIDIndex As Int16 = reader.GetOrdinal("EntityID")
                    Dim lintESourceIDIndex As Int16 = reader.GetOrdinal("ESourceID")
                    Dim lstrESourceNameIndex As Int16 = reader.GetOrdinal("ESourceName")
                    Dim lstrSourceNameIndex As Int16 = reader.GetOrdinal("SourceName")
                    Dim lstrSourceTypeCode As Int16 = reader.GetOrdinal("SourceTypeCode")
                    'Dim lstrSourceDate As Int16 = reader.GetOrdinal("SourceDate")
                    Dim lstrAccessStatus As Int16 = reader.GetOrdinal("AccessStatus")
                    Dim lblnHasAnyDoubts As Int16 = reader.GetOrdinal("HasAnyDoubts")
                    'Dim lintLastUserID As Int16 = reader.GetOrdinal("LastUserID")
                    Dim lstrESourceCode As Int16 = reader.GetOrdinal("ESourceCode")
                    'Dim lstrPublicFilingDateCol As Int16 = reader.GetOrdinal("PublicFilingDateCol")
                    'Dim lstrPublicSourceCol As Int16 = reader.GetOrdinal("PublicSourceCol")
                    'Dim lstrResearchSourceCol As Int16 = reader.GetOrdinal("ResearchSourceCol")
                    Dim lblnIsND As Int16 = reader.GetOrdinal("IsND")
                    Dim lblnIsNIL As Int16 = reader.GetOrdinal("IsNIL")
                    While reader.Read()
                        lobjData = New CurrentDataSources() With { _
                         .ListingID = DBParseUtils.GetFieldValueInt32(reader.GetInt32(lintListingIDIndex)), _
                         .EntityID = DBParseUtils.GetFieldValueInt32(reader.GetInt32(lintEntityIDIndex)), _
                         .ESourceID = DBParseUtils.GetFieldValueInt32(reader.GetByte(lintESourceIDIndex)), _
                         .ESourceName = DBParseUtils.GetFieldValueString(reader.GetString(lstrESourceNameIndex)), _
                         .SourceName = DBParseUtils.GetFieldValueString(reader.GetString(lstrSourceNameIndex)), _
                         .SourceTypeCode = DBParseUtils.GetFieldValueString(reader.GetString(lstrSourceTypeCode)), _
                         .HasAnyDoubts = DBParseUtils.GetFieldValueString(reader.GetBoolean(lblnHasAnyDoubts)), _
                         .ESourceCode = DBParseUtils.GetFieldValueString(reader.GetString(lstrESourceCode)), _
                         .IsND = DBParseUtils.GetFieldValueString(reader.GetBoolean(lblnIsND)), _
                         .IsNIL = DBParseUtils.GetFieldValueString(reader.GetBoolean(lblnIsNIL)), _
                         .AccessStatus = DBParseUtils.GetFieldValueString(reader.GetString(lstrAccessStatus)) _
                        }
                        lstData.Add(lobjData)
                    End While
                End Using
            End Using
            Return lstData
        Finally
        End Try
    End Function

    ''' <summary>
    ''' Retrive data for FL Listing Categories.
    ''' </summary>
    ''' <param name="mintProjectID"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetColumnListFLData(ByVal mintProjectID As Integer) As DataSet
        Return DataFactory.CreateDataBase().ExecuteDataSet("CR_sp_FL_Listing", {mintProjectID})
    End Function

    Public Sub HiddenColumnsFL(ByVal mintProjectID As Integer, ByVal pstrHiddenColumns As String)
        DataFactory.CreateDataBase().ExecuteNonQuery("CR_sp_FL_HiddenColumns", {mintProjectID, pstrHiddenColumns})
    End Sub

    Public Function RetrieveHiddenColumns(ByVal pintProjectID As Integer) As String
        Return DataFactory.CreateDataBase().ExecuteScalar("CR_sp_FL_RetrieveHiddenColumns", {pintProjectID})
    End Function

    Public Sub InsertShortCutEntity(ByVal pintProjectID As Integer, ByVal pstrXML As String)
        DataFactory.CreateDataBase().ExecuteNonQuery("CR_sp_FL_InsertShortCutEntity", {pintProjectID, pstrXML})
    End Sub

    Public Sub InsertShortCut(ByVal pintProjectID As Integer, ByVal pstrXML As String)
        DataFactory.CreateDataBase().ExecuteNonQuery("CR_sp_FL_InsertShortCut", {pintProjectID, pstrXML})
    End Sub
#End Region
End Class
